package com.bootdo.front.controller;

import com.bootdo.common.domain.DictDO;
import com.bootdo.common.service.DictService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.CompanyDO;
import com.bootdo.system.domain.SceneryArticleDO;
import com.bootdo.system.domain.WorkDO;
import com.bootdo.system.service.CompanyService;
import com.bootdo.system.service.SceneryArticleService;
import com.bootdo.system.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/front")
@Slf4j
public class FrontDataController {

    @Autowired
    private DictService dictService;

    @Autowired
    private SceneryArticleService sceneryArticleService;

    @Autowired
    private WorkService workService;

    @Autowired
    private CompanyService companyService;

    /**
     * 获取数据字典数据
     * @return
     */
    @PostMapping("/getDictData")
    @ResponseBody
    public R getDictData() {
        Map<String, Object> map = new HashMap<String, Object>();
        //电话
        map.put("type", "telephone");
        List<DictDO> dictList1 = dictService.list(map);
        //网址
        map.put("type", "website");
        List<DictDO> dictList2 = dictService.list(map);
        //地址
        map.put("type", "address");
        List<DictDO> dictList3 = dictService.list(map);
        //邮箱
        map.put("type", "email");
        List<DictDO> dictList4 = dictService.list(map);
        map.put("telephone", CollectionUtils.isEmpty(dictList1) ? null:dictList1.get(0).getValue());
        map.put("website", CollectionUtils.isEmpty(dictList2) ? null:dictList2.get(0).getValue());
        map.put("address", CollectionUtils.isEmpty(dictList3) ? null:dictList3.get(0).getValue());
        map.put("email", CollectionUtils.isEmpty(dictList4) ? null:dictList4.get(0).getValue());
        return R.ok(map);
    }

    /**
     * 分页获取新闻列表信息
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/listNews")
    public PageUtils listNews(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        int total = sceneryArticleService.count(query);
        PageUtils pageUtils = new PageUtils(articleList, total);
        return pageUtils;
    }

    /**
     * 获取新闻列表信息
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/listData")
    public List<SceneryArticleDO> listData(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<SceneryArticleDO> articleList = sceneryArticleService.list(query);
        return articleList;
    }

    /**
     * 获取人才招聘列表信息
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/listWork")
    public List<WorkDO> listWork(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<WorkDO> list = workService.list(query);
        return list;
    }

    /**
     * 获取合作伙伴列表信息
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/listCompany")
    public List<CompanyDO> listCompany(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<CompanyDO> list = companyService.list(query);
        return list;
    }

}
